package com.kefu.admin.modules.sys.controller;

import com.kefu.admin.modules.sys.model.AreaModel;
import com.kefu.admin.modules.sys.service.AreaService;
import com.kefu.admin.modules.sys.vo.base.ResponseVo;
import com.kefu.admin.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created by TWD on 2018/10/17.
 */

@Controller
@RequestMapping("/sys/area")
public class AreaController {
    private static final Logger logger = LoggerFactory.getLogger(AreaController.class);

    @Autowired
    private AreaService areaService;


    @RequestMapping("/list")
    @ResponseBody
    public ResponseVo list(@RequestParam Map<String, Object> params) {
        try {
            if(null!=params.get("search") && !"".equals(params.get("search"))){
                params.put("py",params.get("search"));
            }
            if(null!=params.get("areaIds") && !"".equals(params.get("areaIds"))){
                params.put("ids", Arrays.asList(params.get("areaIds").toString().split(",")));
            }else{
                params.put("ids",new ArrayList<String>());
            }

            List<AreaModel>  areaList = areaService.queryAreaList(params);
            return ResultUtil.success("ok",areaList);
        } catch (Exception e) {
            logger.error("查询行政区域出错:{}",e);
            return ResultUtil.error("查询行政区域出错!");
        }
    }
}
